//
//  UserAccount.swift
//  WB
//
//  Created by leador on 17/4/5.
//  Copyright © 2017年 袁满. All rights reserved.
//

import UIKit

class UserAccount: NSObject,NSCoding {

    var access_token: String?
    
    var expires_in: TimeInterval = 0.0 {
        
        didSet {
            
            expires_date = Date(timeIntervalSinceNow:expires_in)
            
        }
        
    }
    
    var remind_in:TimeInterval = 0.0
    
    var uid:String?
    
    var expires_date:Date?
    
    var avatar_hd:String?
    
    var name:String?
    
    init(dict:[String:AnyObject?]) {
        
        super.init()
        
        setValuesForKeys(dict)
    }
    
    override func setValue(_ value: Any?, forKey key: String) {
        super.setValue(value!, forKey: key)
    }
    
    //重写属性
    override var description: String {
        return dictionaryWithValues(forKeys: ["access_token","expires_date","uid","name","avatar_hd","avatar_hd"]).description
    }
    

    public func encode(with aCoder: NSCoder) {
        aCoder.encode(access_token, forKey: "access_token")
        aCoder.encode(uid, forKey: "uid")
        aCoder.encode(expires_date, forKey: "expires_date")
        aCoder.encode(avatar_hd, forKey: "avatar_hd")
        aCoder.encode(name, forKey: "name")
    }
    
    public required init?(coder aDecoder: NSCoder) {
        access_token = aDecoder.decodeObject(forKey: "access_token") as? String
        uid = aDecoder.decodeObject(forKey: "uid") as? String
        expires_date = aDecoder.decodeObject(forKey: "expires_date") as? Date
        avatar_hd = aDecoder.decodeObject(forKey: "avatar_hd") as? String
        name = aDecoder.decodeObject(forKey: "name") as? String
    }
    
}
